const express = require('express')
const app = express()
app.use(require('cors')()) //允许跨域
app.use(express.json()) //识别客户端传递过来的json
app.use('/uploads', express.static(__dirname + '/uploads')) //静态托管，
app.use('/admin', express.static(__dirname + '/admin')) //admin
app.use('/', express.static(__dirname + '/web')) //web
app.use('/test', express.static(__dirname + '/test')) //test

require('./routes/admin/index.js')(app) //admin api router
require('./routes/web/index.js')(app) //web api router
require('./plugins/db.js')(app)//数据库连接

app.set('secret','jojo')
/* //新增文章
app.post('/api/articles', async (req, res) => {
  const article = await Article.create(req.body)
  res.send(article)
})
//文章列表
app.get('/api/articles', async (req, res) => {
  const articlelist = await Article.find()
  res.send(articlelist)
})
//删除文章 
app.delete('/api/articles/:id', async (req, res) => {
  await Article.findByIdAndDelete(req.params.id)
  res.send({
    status: true
  })
})
//文章详情
app.get('/api/articles/:id', async (req, res) => {
  const article = await Article.findById(req.params.id)
  res.send(article)
})
//修改文章
app.put('/api/articles/:id', async (req, res) => {
  const article = await Article.findByIdAndUpdate(req.params.id, req.body)
  res.send(article)
}) */
/* app.get('/', async (req, res) => {
  res.send('index')
}) */
app.listen(80, () => {
  console.log('http://localhost:80');

})